unit NTTypes;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

interface

uses
  Classes, SysUtils, Graphics, Controls;

type
  TEscapeAction = (eaBack, eaClear, eaClearBack, eaClose, eaNone);
  TEditType = (etInteger, etFloat, etCurrency, etPercent);
  TTextAlign = (taLeft, taRight);
  TMaskType = (mtData, mtTelefone, mtTelFixo, mtCelular, mtCPF, mtCNPJ, mtPIS, mtPlaca, mtCustom);
  TAlternableMask = set of (amData, amTelefone, amTelFixo, amCelular, amCPF, amCNPJ, amPIS, amPlaca);

  TColors = class(TPersistent)
  private
    FFocusColor,
    FRightColor,
    FWrongColor : TColor;
    function GetFocusColor: TColor;
    function GetRightColor: TColor;
    function GetWrongColor: TColor;
    procedure SetFocusColor(const AValue: TColor);
    procedure SetRightColor(const AValue: TColor);
    procedure SetWrongColor(const AValue: TColor);
  public
    constructor Create;
  published
    property FocusColor: TColor
      read GetFocusColor write SetFocusColor default $00FFEFDF;
    property RightColor: TColor
      read GetRightColor write SetRightColor default $00DFFFEF;
    property WrongColor: TColor
      read GetWrongColor write SetWrongColor default $00EFDFFF;
  end;

  TAttributes = class(TPersistent)
  private
    FColors: TColors;
    FEscapeAction: TEscapeAction;
    FColorize,
    FEnterAsTab,
    FRequired    : Boolean;
    FParent      : TComponent;
    function GetColorize: Boolean;
    function GetEnterAsTab: Boolean;
    function GetEscapeAction: TEscapeAction;
    function GetRequired: Boolean;
    procedure SetColorize(const AValue: Boolean);
    procedure SetEnterAsTab(const AValue: Boolean);
    procedure SetEscapeAction(const AValue: TEscapeAction);
    procedure SetRequired(const AValue: Boolean);
  public
    constructor Create(TheParent: TComponent);
  published
    property Colors: TColors
      read FColors write FColors;
    property EscapeAction: TEscapeAction
      read GetEscapeAction write SetEscapeAction default eaBack;
    property Colorize: Boolean
      read GetColorize write SetColorize default True;
    property EnterAsTab: Boolean
      read GetEnterAsTab write SetEnterAsTab default True;
    property Required: Boolean
      read GetRequired write SetRequired default False;
  end;

  { TCaptions }

  TCaptions = class(TPersistent)
    private
      FMenuItem,
      FCloseTab,
      FCloseAllTabs,
      FCloseAllButThis: TCaption;
    public
      constructor Create;
    published
      property MenuItem: TCaption read FMenuItem write FMenuItem;
      property CloseTab: TCaption read FCloseTab write FCloseTab;
      property CloseAllTabs: TCaption read FCloseAllTabs write FCloseAllTabs;
      property CloseAllButThis: TCaption read FCloseAllButThis write FCloseAllButThis;
  end;

implementation

uses
  NTCustomControls;

{ TColors }

constructor TColors.Create;
begin
  FFocusColor := $00FFEFDF;
  FRightColor := $00DFFFEF;
  FWrongColor := $00EFDFFF;
end;

function TColors.GetFocusColor: TColor;
begin
  Result := FFocusColor;
end;

function TColors.GetRightColor: TColor;
begin
  Result := FRightColor;
end;

function TColors.GetWrongColor: TColor;
begin
  Result := FWrongColor;
end;

procedure TColors.SetFocusColor(const AValue: TColor);
begin
  if FFocusColor <> AValue then
    FFocusColor := AValue;
end;

procedure TColors.SetRightColor(const AValue: TColor);
begin
  if FRightColor <> AValue then
    FRightColor := AValue;
end;

procedure TColors.SetWrongColor(const AValue: TColor);
begin
  if FWrongColor <> AValue then
    FWrongColor := AValue;
end;

{ TAttributes }

constructor TAttributes.Create(TheParent: TComponent);
begin
  FParent := TheParent;
  FColors := TColors.Create;
  FEnterAsTab := FParent.ClassType <> TNTMemo;
  FEscapeAction := eaBack;
  FColorize := True;
  FRequired := False;
end;

function TAttributes.GetColorize: Boolean;
begin
  Result := FColorize;
end;

function TAttributes.GetEnterAsTab: Boolean;
begin
  Result := FEnterAsTab;
end;

function TAttributes.GetEscapeAction: TEscapeAction;
begin
  Result := FEscapeAction;
end;

function TAttributes.GetRequired: Boolean;
begin
  Result := FRequired;
end;

procedure TAttributes.SetColorize(const AValue: Boolean);
begin
  if FColorize <> AValue then
  begin
    if FRequired then
      FColorize := True
    else
      FColorize := AValue;
  end;
end;

procedure TAttributes.SetEnterAsTab(const AValue: Boolean);
begin
  if FEnterAsTab <> AValue then
    if FParent.ClassType <> TNTMemo then
      FEnterAsTab := AValue
    else
      FEnterAsTab := False;
end;

procedure TAttributes.SetEscapeAction(const AValue: TEscapeAction);
begin
  if FEscapeAction <> AValue then
    FEscapeAction := AValue;
end;

procedure TAttributes.SetRequired(const AValue: Boolean);
begin
  if FRequired <> AValue then
  begin
    if AValue then
    begin
      FRequired := True;
      FColorize := True;
    end
    else
      FRequired := False;
  end;
end;

{ TCaptions }

constructor TCaptions.Create;
begin
  FMenuItem := '';
  FCloseTab := '';
  FCloseAllTabs := '';
  FCloseAllButThis := '';
end;

end.

